package com.oplus.Provider.tree;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;

import com.oplus.model.oTree;

public class TreeLabelProvider extends LabelProvider implements ILabelProvider{
	public String getText(Object obj) {
		if (obj instanceof oTree){
			oTree tree = (oTree)obj;
			return tree.getName();
		}
		return "";
	}
	public Image getImage(Object obj) {
		String imageKey = ISharedImages.IMG_OBJ_ELEMENT;
		Image image = PlatformUI.getWorkbench().getSharedImages().getImage(imageKey);
		if (obj instanceof oTree){
			oTree tree = (oTree)obj;
			if(tree.getImg() != null){
				InputStream is = TreeLabelProvider.class.getResourceAsStream(tree.getImg());
				image = new Image(null,is);
			}else{
				imageKey = ISharedImages.IMG_OBJ_FOLDER;
				image = PlatformUI.getWorkbench().getSharedImages().getImage(imageKey);
			}
		}
		return image;
	}
	
}
